var express = require('express');
var router = express.Router();
var fs = require("fs");
var logger = require('../config/logConfig').logger;

/* GET users listing. */
router.get('/', function (req, res, next) {
  res.send({ 'name': '1234516' });
});

/**
 * 获取用户列表
 */
router.get('/listUsers', function (req, res) {
  fs.readFile(__dirname + "/" + "users.json", 'utf8', function (err, data) {
    console.log(data);
    res.end(data);
  });
});

router.get('/:id', function (req, res) {
  fs.readFile(__dirname + '/' + "users.json", 'utf8', function (err, data) {
    data = JSON.parse(data);
    var user = data['user' + req.params.id];
    console.log(user);
    logger.info(user);
    res.end(JSON.stringify(user));
  });
});

router.post('/add', function (req, res) {
  console.log(req.body);
  logger.info(req.body);
  res.send({ 'code': 0 });
  res.end();
});

module.exports = router;
